package com.express.e.root.controller;

import com.express.e.root.annotation.ResponseBody;
import com.express.e.root.bean.Message;
import com.express.e.root.service.ConsoleService;
import com.express.e.root.service.impl.ConsoleServiceImpl;
import com.express.e.root.utils.JSONUtil;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ConsoleController {
    private ConsoleService consoleService = new ConsoleServiceImpl();
    @ResponseBody(value = "/console.do")
    public String queryStatus(HttpServletRequest req, HttpServletResponse resp) {
        resp.setCharacterEncoding("utf-8");
        List<Map<String, Integer>> data = new ArrayList<Map<String, Integer>>();
        HashMap<String, Integer> stringIntegerHashMap = new HashMap<>();
        stringIntegerHashMap.put("快递员人数",consoleService.queryCourierNum());
        stringIntegerHashMap.put("快递员日注册量",consoleService.queryCourierRegisterLastDay());
        stringIntegerHashMap.put("新增数量",consoleService.queryDeliveryFetchLastDay());
        stringIntegerHashMap.put("日派单量",consoleService.queryDeliveryRegisterLastDay());
        stringIntegerHashMap.put("待取件数",consoleService.queryDeliveryFetchNum());
        stringIntegerHashMap.put("总快件数",consoleService.queryDeliveryNum());
        stringIntegerHashMap.put("用户人数",consoleService.queryUserTotalNum());
        stringIntegerHashMap.put("用户日注册量",consoleService.queryUserRegisterLastDay());
        data.add(stringIntegerHashMap);
        Message msg = new Message(200, "控制台查询成功", data);
        String toJson = JSONUtil.toJson(msg);
        System.out.println(toJson);
        return toJson;
    }
}
